package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * 工单状态
 * @author haibin.zhang
 */
@Getter
public enum WorkOrderStatusEnum {
    /**
     *
     */
    UNACCEPTED(1,"","enum.workOrderStatus.name.unaccepted"),


    ONGOING(2,"","enum.workOrderStatus.name.ongoing"),


    FINISH(3,"","enum.workOrderStatus.name.finish"),


    CLOSE(4,"","enum.workOrderStatus.name.close"),

    UNKNOWN(404, "unknown", "enum.callLogResult.name.unknown");

    private int code;
    private String alias;
    private String name;

    WorkOrderStatusEnum(int code, String alias, String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return WxErrorCodeEnum
     */
    public static WorkOrderStatusEnum getByCode(Integer code) {
        for (WorkOrderStatusEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<WorkOrderStatusEnum>
     */
    public static List<WorkOrderStatusEnum> getAllEnum() {
        List<WorkOrderStatusEnum> list = new ArrayList<>();
        for (WorkOrderStatusEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取需要的枚举
     * @return List<WorkOrderStatusEnum>
     */
    public static List<WorkOrderStatusEnum> getNeedEnum() {
        List<WorkOrderStatusEnum> list = new ArrayList<>();
        for (WorkOrderStatusEnum cache : values()) {
            if (cache.getCode() < 10) {
                list.add(cache);
            }
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
